// import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
import QtQuick 1.1

Item {




    property string langID
    XmlListModel {
        id: xmlCurrentWeather
        source: "data/weatherExample.xml"
//source: "http://api.wunderground.com/api/44cf3daadaaf3596/conditions/forecast/hourly/q/autoip.xml"
        query: "/response/current_observation"
        XmlRole { name: "cityName"; query: "display_location/full/string()" }
        XmlRole { name: "weatherDescription"; query: "weather/string()" }
        XmlRole { name: "temp_f"; query: "temp_f/number()" }
        XmlRole { name: "temp_c"; query: "temp_c/number()" }
        XmlRole { name: "relative_humidity"; query: "relative_humidity/string()" }
        XmlRole { name: "wind_dir"; query: "wind_dir/string()" }
        XmlRole { name: "wind_mph"; query: "wind_mph/string()" }
        XmlRole { name: "pressure_mb"; query: "pressure_mb/string()" }
        XmlRole { name: "pressure_trend"; query: "pressure_trend/string()" }
        XmlRole { name: "dewpoint_f"; query: "dewpoint_f/string()" }
        XmlRole { name: "dewpoint_c"; query: "dewpoint_c/string()" }
        XmlRole { name: "icon"; query: "icon/string()" }
    }
    XmlListModel {
        id: xmlNextDay
        source: "data/weatherExample.xml"
    //source: "http://api.wunderground.com/api/44cf3daadaaf3596/conditions/forecast/hourly/q/autoip.xml"
        query: "/response/forecast/simpleforecast/forecastdays/forecastday[position() < 4]"
        XmlRole { name: "weekDay"; query: "date/weekday/string()" }
        XmlRole { name: "weatherDescription"; query: "conditions/string()" }
        XmlRole { name: "temp_high_f"; query: "high/fahrenheit/number()" }
        XmlRole { name: "temp_high_c"; query: "high/celsius/number()" }
        XmlRole { name: "temp_low_f"; query: "low/fahrenheit/number()" }
        XmlRole { name: "temp_low_c"; query: "low/celsius/number()" }
        XmlRole { name: "average_humidity"; query: "avehumidity/string()" }
        XmlRole { name: "wind_dir"; query: "avewind/dir/string()" }
        XmlRole { name: "wind_mph"; query: "avewind/mph/number()" }
        XmlRole { name: "icon"; query: "icon/string()" }
        XmlRole { name: "skyicon"; query: "skyicon/string()" }
    }



    ListView {
         width: 400; height: 40
         interactive: false
         model: xmlCurrentWeather
         delegate: xmlCurrentWeatherDelegate
     }

    ListView {
        x: 0
        y: 130
         width: 400; height: 500
         interactive: false
         model: xmlNextDay
         delegate: xmlNextDayDelegate
         spacing: 2
     }

    Component{
        id: xmlCurrentWeatherDelegate

        Rectangle {
            MouseArea {
                id: mousearea1
                x: 0
                y: 0
                anchors.rightMargin: 0
                anchors.bottomMargin: 0
                anchors.leftMargin: 0
                anchors.topMargin: 0
                anchors.fill: parent
                onClicked: {
                    xmlCurrentWeather.reload()
                }


            }
            Text {
                id: text50
                x: 12
                y: 9
                font.bold: true
                font.pixelSize: 27
            }
            width: 400
            height: 128
             color: "#206088"

             Image {
                 id: image1
                 x: 271
                 y: 0
                 width: 128
                 height: 128
                 source: "Assets/weather_icons/mostlysunny.png"
             }

             Text {
                 id: text1
                 x: 173
                 y: 45
                 text: temp_f+ " °F"
                 font.family: "Georgia"
                 font.bold: true
                 font.pixelSize: 31
             }

             Text {
                 id: text2
                 x: 26
                 y: 58
                 text: weatherDescription
                 font.family: "Georgia"
                 font.pixelSize: 12
             }

             Text {
                 id: text3
                 x: 26
                 y: 82
                 text: if(langID == "1") "Wind: " +wind_dir+" at " + wind_mph+" mph";
                        else "Viento: " +wind_dir+" at " + wind_mph+" mph";
                 font.family: "Georgia"
                 font.pixelSize: 12
             }

             Text {
                 id: text4
                 x: 26
                 y: 105
                 text: if(langID == "1") "Humidity: "+ relative_humidity;
                        else "Humedad: "+ relative_humidity;
                 font.family: "Georgia"
                 font.pixelSize: 12
             }

             Text {
                 id: text5
                 x: 12
                 y: 10
                 text: if(langID == "1") "Today";else "Hoy";
                 font.bold: true
                 font.pixelSize: 27
             }

        }
    }
      Component{
            id: xmlNextDayDelegate

            Rectangle {


                width: 400
                height: 128
                 color: "#206088"

                 Image {
                     id: image1
                     x: 271
                     y: 0
                     width: 128
                     height: 128
                     source: "Assets/weather_icons/mostlysunny.png"
                 }

                 Text {
                     id: text1
                     x: 166
                     y: 42
                     text: if(langID == "1") "High: "+temp_high_f+"°F";
                            else "Alta: "+temp_high_f+"°F";
                     font.family: "Georgia"
                     font.bold: true
                     font.pixelSize: 16
                 }

                 Text {
                     id: text2
                     x: 173
                     y: 67
                     width: 37
                     height: 18
                     text: if(langID == "1") "Low: "+temp_low_f+"°F";
                           else "Bajo: "+temp_low_f+"°F";
                     font.bold: true
                     font.family: "Georgia"
                     font.pixelSize: 16
                 }

                 Text {
                     id: text3
                     x: 20
                     y: 78
                     text: if(langID == "1") "Wind: "+wind_mph+" mph at "+wind_dir;
                        else "Viento: "+wind_mph+" mph at "+wind_dir;
                     font.family: "Georgia"
                     font.pixelSize: 12
                 }

                 Text {
                     id: text4
                     x: 21
                     y: 101
                     text: if(langID == "1") "Average Humidity: "+ average_humidity +"%";
                            else "Promedio Humedad: "+ average_humidity +"%";
                     font.family: "Georgia"
                     font.pixelSize: 12
                 }

                 Text {
                     id: text5
                     x: 12
                     y: 9
                     text: weekDay
                     font.bold: true
                     font.pixelSize: 27
                 }

                 Text {
                     id: text6
                     x: 26
                     y: 46
                     text: weatherDescription
                     font.pixelSize: 12
                 }

            }
        }
}






//Michal
